package model;

import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.tree.DefaultMutableTreeNode;

import org.jdom.Content;
import org.jdom.Element;

import util.Util;

public class Node extends DefaultMutableTreeNode 
{

	private Element element;

	public Node() {
	    element = new Element("tabela");
	}
	
	public Node(Element e) {
		this.element = e;
	}
	
	public Element getElement() {
		return element;
	}
	
	public void setElement(Element element) {
		this.element = element;
	}
	
	@Override
	public String toString() {
		return  "" + element.getName() 
				+ (( element.getAttribute("nome") != null ? " nome=" + element.getAttribute("nome").getValue() : "" ) + " " )    
				+ ( element.getText() != null ?  element.getText() : "" ) 
				+ ( element.getAttribute("restricao") != null ? ", restricao=" + element.getAttribute("restricao").getValue() : "" );
	}
	
	public ImageIcon getIcon() {
		return Util.createImageIcon("images/" + element.getName() + ".png");
	}

	public boolean isName(String nome)
	{
		return element.getName().equals(nome);
	}
	
	public String getName()
	{
	    return element.getName();
	}
	
	public void setNome(String nome) 
	{
	    element.setAttribute("nome",nome);
	}

	

	public Element addContent(Content child) {
	    return element.addContent(child);
	}

	public Element getChild(String name) {
	    return element.getChild(name);
	}

	public List removeContent() {
	    return element.removeContent();
	}
	
	
	

}
